home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / StyledDocument.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  174 lines

  1. /*
  2.  * @(#)StyledDocument.java    1.13 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.text;
  21.  
  22. import java.awt.Font;
  23. import java.awt.Color;
  24.  
  25. /**
  26.  * Interface for a generic styled document.
  27.  * 
  28.  * @author  Timothy Prinzing
  29.  * @version 1.13 04/09/98
  30.  */
  31. public interface StyledDocument extends Document {
  32.  
  33.     /**
  34.      * Adds a new style into the logical style hierarchy.  Style attributes
  35.      * resolve from bottom up so an attribute specified in a child
  36.      * will override an attribute specified in the parent.
  37.      *
  38.      * @param nm   the name of the style (must be unique within the
  39.      *   collection of named styles).  The name may be null if the style 
  40.      *   is unnamed, but the caller is responsible
  41.      *   for managing the reference returned as an unnamed style can't
  42.      *   be fetched by name.  An unnamed style may be useful for things
  43.      *   like character attribute overrides such as found in a style 
  44.      *   run.
  45.      * @param parent the parent style.  This may be null if unspecified
  46.      *   attributes need not be resolved in some other style.
  47.      * @return the style
  48.      */
  49.     public Style addStyle(String nm, Style parent);
  50.  
  51.     /**
  52.      * Removes a named style previously added to the document.  
  53.      *
  54.      * @param nm  the name of the style to remove
  55.      */
  56.     public void removeStyle(String nm);
  57.  
  58.     /**
  59.      * Fetches a named style previously added.
  60.      *
  61.      * @param nm  the name of the style
  62.      * @return the style
  63.      */
  64.     public Style getStyle(String nm);
  65.  
  66.     /**
  67.      * Changes the content element attributes used for the given range of 
  68.      * existing content in the document.  All of the attributes 
  69.      * defined in the given Attributes argument are applied to the 
  70.      * given range.  This method can be used to completely remove
  71.      * all content level attributes for the given range by 
  72.      * giving an Attributes argument that has no attributes defined 
  73.      * and setting replace to true.
  74.      *
  75.      * @param offset the start of the change >= 0
  76.      * @param length the length of the change >= 0
  77.      * @param s    the non-null attributes to change to.  Any attributes
  78.      *  defined will be applied to the text for the given range.
  79.      * @param replace indicates whether or not the previous 
  80.      *  attributes should be cleared before the new attributes
  81.      *  as set.  If true, the operation will replace the 
  82.      *  previous attributes entirely.  If false, the new
  83.      *  attributes will be merged with the previous attributes.
  84.      */
  85.     public void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace);
  86.  
  87.     /**
  88.      * Sets paragraph attributes.
  89.      *
  90.      * @param offset the start of the change >= 0
  91.      * @param length the length of the change >= 0
  92.      * @param s    the non-null attributes to change to.  Any attributes
  93.      *  defined will be applied to the text for the given range.
  94.      * @param replace indicates whether or not the previous 
  95.      *  attributes should be cleared before the new attributes
  96.      *  are set.  If true, the operation will replace the 
  97.      *  previous attributes entirely.  If false, the new
  98.      *  attributes will be merged with the previous attributes.
  99.      */
  100.     public void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace);
  101.  
  102.     /**
  103.      * Sets the logical style to use for the paragraph at the
  104.      * given position.  If attributes aren't explicitly set
  105.      * for character and paragraph attributes they will resolve
  106.      * through the logical style assigned to the paragraph, which
  107.      * in turn may resolve through some hierarchy completely
  108.      * independent of the element hierarchy in the document.
  109.      *
  110.      * @param pos the starting position >= 0
  111.      * @param s the style to set
  112.      */
  113.     public void setLogicalStyle(int pos, Style s);
  114.  
  115.     /**
  116.      * Gets a logical style for a given position in a paragraph.
  117.      *
  118.      * @param p the position >= 0
  119.      * @return the style
  120.      */
  121.     public Style getLogicalStyle(int p);
  122.  
  123.     /**
  124.      * Gets the element that represents the paragraph that
  125.      * encloses the given offset within the document.
  126.      *
  127.      * @param pos the offset >= 0
  128.      * @return the element
  129.      */
  130.     public Element getParagraphElement(int pos);
  131.  
  132.     /**
  133.      * Gets the element that represents the character that
  134.      * is at the given offset within the document.
  135.      *
  136.      * @param pos the offset >= 0
  137.      * @return the element
  138.      */
  139.     public Element getCharacterElement(int pos);
  140.  
  141.  
  142.     /**
  143.      * Takes a set of attributes and turn it into a foreground color
  144.      * specification.  This might be used to specify things
  145.      * like brighter, more hue, etc.
  146.      *
  147.      * @param attr the set of attributes
  148.      * @return the color
  149.      */
  150.     public Color getForeground(AttributeSet attr);
  151.  
  152.     /**
  153.      * Takes a set of attributes and turn it into a background color
  154.      * specification.  This might be used to specify things
  155.      * like brighter, more hue, etc.
  156.      *
  157.      * @param attr the set of attributes
  158.      * @return the color
  159.      */
  160.     public Color getBackground(AttributeSet attr);
  161.  
  162.     /**
  163.      * Takes a set of attributes and turn it into a font
  164.      * specification.  This can be used to turn things like
  165.      * family, style, size, etc into a font that is available
  166.      * on the system the document is currently being used on.
  167.      *
  168.      * @param attr the set of attributes
  169.      * @return the font
  170.      */
  171.     public Font getFont(AttributeSet attr);
  172.  
  173. }
  174.